<?php
/*
Plugin Name: Test Hatforrent
Plugin URI: http://www.hatforrent.com
Description: Test on hatforrent
Author: HoanBN
Version: 1.0
Author URI: http://www.hatforrent.com
*/

add_action('admin_menu', 'hfr_test_add_options_link');

function hfr_test_add_options_link() {
	add_menu_page('Hatforrent Management', 'Hatforrent Test', 'manage_options', 'Test Hatforrent', 'hfr_test', "image/hatforrent.jpg");	
}

function hfr_test() {
	
	postHatforentUrlWorker();
	
}

function postHatforentUrlWorker() {
	global $wpdb;
	
	$sitemap = "http://basicuse.net/articles/pl/textile/html_css";
	
	$sql = "SELECT * FROM ".$wpdb->prefix."hfr_url_craw WHERE sitemap = '".$sitemap."'";

	$data = $wpdb->get_row($sql);
	
	hfr_debug($data);
	
	$urlWorker = "http://localhost:8888/hatforentappengineurlworker";
	
	$params = array(
		//'link'					=> 'http://basicuse.net/articles/pl/textile/html_css/social_media_icons_with_slide_up_and_down_animation_using_only_css3',
		'sitemap' 				=> $data->sitemap,
		'blog'					=> $data->blog,
		'reglink' 				=> $data->reglink,
		'type'					=> 'wordpress',
		'tag'					=> $data->tag,
		'linkSelecterJs' 		=> $data->linkSelecterJs,
		'activeLinkJs' 			=> $data->activeLinkJs,
		'linkSelecter' 			=> $data->linkSelecter,
		'getAll' 				=> $data->getAll,
		'titleSelecter' 		=> $data->titleSelecter,
		'contentSelecter' 		=> $data->contentSelecter,
		'removeSelecter' 		=> $data->removeSelecter,
		'customSelecter' 		=> $data->customSelecter,
		'category' 				=> $data->category,
		'typelink' 				=> $data->typelink,
		'source' 				=> $data->source,
		'sourcetype' 			=> $data->sourcetype,
		'source_image' 			=> $data->source_image,
		'remove_tag_a' 			=> $data->remove_tag_a,
		'userBlog' 				=> $data->userBlog,
		'activeContentJs' 		=> $data->activeContentJs,
		'arrLink' 				=> $data->arrLink,
		'username'				=> get_option("hfr_blog_username"),
		'password'				=> get_option("hfr_blog_password"),
	);
	
	$content = hfr_remote_post($urlWorker, $params);
	
}

function postGetLinkWorkerUrl() {
	$url = "http://localhost:8888/get-link-worker-url";
	
	$params = array(
		"link" 				=> "http%3A%2F%2Fbasicuse.net%2Farticles%2Fpl%2Ftextile%2F",
		"blog"				=> "http%3A%2F%2Flocalhost%3A9080",
		"sitemap"			=> "http%3A%2F%2Fbasicuse.net%2Farticles%2Fpl%2Ftextile%2Fhtml_css",
		"titleSelecter"		=> "",
		"contentSelecter"	=> "",
		"removeSelecter"	=> "",
		"customSelecter"	=> "%0A%2F%2FJs+function+must+return+array+of+string+link+%0Afunction+beforePost%28document%29+%7B%0A++++%0A++++var+data+%3D+new+Array%28%29%3B%0A++++data%5B%27title%27%5D+%3D+document.select%28%27.content+%3E+h1%3Afirst-child%27%29.text%28%29%3B%0A++++%0A++++var+abc+%3D+new+com.xty.Elements%28%29%3B++++%0A++++abc+%3D+document.select%28%27.attr-long+pre%27%29%3B%0A++++%0A++++var+a+%3D+new+com.xty.Elements%28%29%3B%0A%09var+content+%3D+document.select%28%27.attr-long%27%29.html%28%29%3B%0A%09%0A%09for+%28var+i+%3D+0%3B+i+%3C+abc.size%28%29%3B+i%2B%2B%29+%7B%0A%09%09a+%3D+abc.get%28i%29.html%28%29%3B%0A%09%09var+b+%3D+a.replaceAll%28%22%5B%5Cn%5D%2B%22%2C+%22%22%29%3B%0A%09%09content+%3D+content.replace%28a%2C+b%29%3B%0A%09%7D%0A%09%0A++++var+post_tag+%3D+new+com.xty.Elements%28%29%3B%0A%0A++++post_tag+%3D+document.select%28%27.attr-keyw+a%27%29%3B%0A++++data%5B%27tag%27%5D%3D%22%22%3B%0A++++for%28i%3D0%3Bi+%3C+post_tag.size%28%29%3Bi%2B%2B%29%0A++++%7B%0A++++++++data%5B%27tag%27%5D+%2B%3D+post_tag.get%28i%29.text%28%29%2B%22%2C%22%3B++++%0A++++%7D%0A++++%0A%09data%5B%27content%27%5D+%3D+content%3B%0A%09return+data%3B%0A%7D",
		"category"			=> "",
		"typelink"			=> "nofollow",
		"source"			=> "yes",
		"sourcetype"		=> "text",
		"source_image"		=> "source",
		"remove_tag_a"		=> "yes",
		"userBlog"			=> "hoanbn.php%40gmail.com",
		"reglink"			=> ".class-article+h2+a",
		"tag" 				=> "",
		"linkSelecterJs"	=> "",
		"activeLinkJs"		=> "no",
		"linkSelecter"		=> ".class-article+h2+a",
		"linkUpdate"		=> "http%3A%2F%2Fbasicuse.net%2Farticles%2Fpl%2Ftextile%2F",
		"activeContentJs"	=>	"yes",
	);
	
}